package com.yoomiito.app.ui.my.angle

import cn.droidlover.xdroidmvp.net.ApiException
import cn.droidlover.xdroidmvp.net.ApiSubscriber
import cn.droidlover.xdroidmvp.net.BaseModel
import cn.droidlover.xdroidmvp.net.XApi
import com.yoomiito.app.base.AppConfig
import com.yoomiito.app.base.BaseActPresenter
import com.yoomiito.app.model.my.AngleUserInfo
import com.yoomiito.app.net.YmApi

class AngleUserInfoPresenter(appConfig: AppConfig) :BaseActPresenter<AngleUserInfoActivity>(appConfig){

    fun upload(name:String,mobile:String,identity:String,areaName:String,address:String,mailbox:String){
        YmApi.getYmService()
                .uploadUserInfo(name, mobile, identity, areaName, address, mailbox)
                .compose(v.bindToLifecycle())
                .compose(XApi.getApiTransformerNoData<BaseModel<*>>())
                .compose(XApi.getScheduler())
                .subscribe(object :ApiSubscriber<BaseModel<*>>(handleException()){
                    override fun onSuccess(t: BaseModel<*>?) {
                        v.uploadResult()
                    }

                    override fun onFail(error: ApiException?) {
                        v.dismissLoading()
                    }

                })
    }

    fun getInfo(){
        YmApi.getYmService()
                .angleUserInfo()
                .compose(v.bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(object :ApiSubscriber<AngleUserInfo>(handleException()){
                    override fun onSuccess(t: AngleUserInfo?) {
                        v.setData(t)
                    }

                    override fun onFail(error: ApiException?) {
                        v.dismissLoading()
                    }

                })
    }
}